package com.sharer.last.controller;


import com.sharer.last.base.constant.CommonConstant;
import com.sharer.last.base.model.R;
import com.sharer.last.model.dto.comment.CommentQueryDTO;
import com.sharer.last.model.vo.comment.CommentGeneralVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sharer.last.annotation.AccessLimit;
import com.sharer.last.model.dto.comment.CommentAddDTO;

import com.sharer.last.service.CommentService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 评论
 *
 * @ClassName CommentController
 * @Author wangjin
 * @Date 2023/5/5 21:06
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.BLOG_FRONT_API + "/comment")
public class CommentController {
    @Resource
    CommentService commentService;

    /**
     * 根据页面分页查询评论列表
     *
     * @param commentQueryDTO
     * @return
     */
    @PostMapping("/selectByPage")
    public R selectByPage(@RequestBody @Validated CommentQueryDTO commentQueryDTO) {
        CommentGeneralVO commentGeneralVO = commentService.getCommentByPage(commentQueryDTO);
        return R.ok(commentGeneralVO);
    }

    @AccessLimit(seconds = 30, maxCount = 1, msg = "30秒内只能提交一次评论")
    @PostMapping("/create")
    public R create(@RequestBody @Validated CommentAddDTO comment, HttpServletRequest request) {
        commentService.createComment(comment, request);
        return R.handle();
    }
}
